package cn.congzhou.crm.service.impl;

import cn.congzhou.crm.domain.Customer;
import cn.congzhou.crm.domain.Employee;
import cn.congzhou.crm.mapper.CustomerMapper;
import cn.congzhou.crm.mapper.EmployeeMapper;
import cn.congzhou.crm.query.QueryObject;
import cn.congzhou.crm.service.ICustomerPoolService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomerPoolServiceImpl implements ICustomerPoolService {

    @Autowired
    private CustomerMapper customerMapper;

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public void changeCustomerStatus(Long cusId, Integer status) {
        if(cusId!=null){
            customerMapper.changeCustomerStatus(cusId, status);
        }
    }


    @Override
    public Customer selectByPrimaryKey(Long id) {
        Customer customer = customerMapper.selectByPrimaryKey(id);
        return customer;
    }



    @Override
    public PageInfo<Customer> selectByPage(QueryObject qo) {
//      调用这个类的静态方法处理分页数据
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Customer> list = customerMapper.selectByPage(qo);
//      创建页面信息对象封装起来
        PageInfo<Customer> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public List<Employee> queryNewSeller() {
        List<Employee> employees = employeeMapper.selectAll();
        return employees;
    }
}
